<?php

namespace think\wework\Api;

use think\wework\Abstracts\WeworkApiWithToken;

class Agent extends WeworkApiWithToken
{
    private static ?Agent $instance = null;
    public static function getInstance(): Agent
    {
        if(!self::$instance instanceof Agent) {
            self::$instance = new self();
        }
        return self::$instance;
    }
    /**
     * 获取应用
     * @return array
     */
    public function get(): array
    {
        $query = [
            'agentid' => $this->agentId
        ];
        return $this->httpClient->get('agent/get', compact('query'))->toArray();
    }

    /**
     * 设置应用
     *
     * @param array $json
     * @return array
     */
    public function set(array $json): array
    {
        $json = array_merge(['agentid' => $this->agentId], $json);
        return $this->httpClient->post('agent/set', compact('json'))->toArray();
    }

    /**
     * 获取应用列表
     *
     * @return array
     */
    public function list(): array
    {
        return $this->httpClient->get('agent/list')->toArray();
    }
}
